home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / memory / realloc.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  673b  |  42 lines

  1.  
  2. /*
  3.  *  REALLOC.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <stdlib.h>
  13. #include <errno.h>
  14. #include <string.h>
  15.  
  16. #define buf ((long *)vbuf)
  17.  
  18. void *
  19. realloc(vbuf, bytes)
  20. void *vbuf;
  21. size_t bytes;
  22. {
  23.     void *ptr = NULL;
  24.     int copy;
  25.  
  26.     if (bytes <= 0 && buf) {
  27.     free(buf);
  28.     return(NULL);
  29.     }
  30.     if (buf) {
  31.     copy = buf[-1] - 8;
  32.     if (bytes <= copy)
  33.         return(buf);
  34.     }
  35.     ptr = malloc(bytes);
  36.     if (ptr && buf) {
  37.     movmem(buf, ptr, copy);
  38.     free(buf);
  39.     }
  40.     return(ptr);
  41. }
  42.